<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: samples/cpp/image_alignment.cpp</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">samples/cpp/image_alignment.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>An example using the image alignment ECC algorithm</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">* This sample demonstrates the use of the function</span></div><div class="line"><span class="comment">* findTransformECC that implements the image alignment ECC algorithm</span></div><div class="line"><span class="comment">*</span></div><div class="line"><span class="comment">*</span></div><div class="line"><span class="comment">* The demo loads an image (defaults to fruits.jpg) and it artificially creates</span></div><div class="line"><span class="comment">* a template image based on the given motion type. When two images are given,</span></div><div class="line"><span class="comment">* the first image is the input image and the second one defines the template image.</span></div><div class="line"><span class="comment">* In the latter case, you can also parse the warp&#39;s initialization.</span></div><div class="line"><span class="comment">*</span></div><div class="line"><span class="comment">* Input and output warp files consist of the raw warp (transform) elements</span></div><div class="line"><span class="comment">*</span></div><div class="line"><span class="comment">* Authors: G. Evangelidis, INRIA, Grenoble, France</span></div><div class="line"><span class="comment">*          M. Asbach, Fraunhofer IAIS, St. Augustin, Germany</span></div><div class="line"><span class="comment">*/</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d0/d1c/video_2include_2opencv2_2video_8hpp.html">opencv2/video.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html">opencv2/imgproc.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4e/utility_8hpp.html">opencv2/core/utility.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;time.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;fstream&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d8/dcc/namespacestd.html">std</a>;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> help(<span class="keyword">const</span> <span class="keywordtype">char</span>** argv);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> readWarp(<span class="keywordtype">string</span> iFilename, <a name="_a0"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>&amp; warp, <span class="keywordtype">int</span> motionType);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> saveWarp(<span class="keywordtype">string</span> fileName, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>&amp; warp, <span class="keywordtype">int</span> motionType);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> draw_warped_roi(<a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>&amp; image, <span class="keyword">const</span> <span class="keywordtype">int</span> width, <span class="keyword">const</span> <span class="keywordtype">int</span> height, <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>&amp; W);</div><div class="line"></div><div class="line"><span class="preprocessor">#define HOMO_VECTOR(H, x, y)\</span></div><div class="line"><span class="preprocessor">    H.at&lt;float&gt;(0,0) = (float)(x);\</span></div><div class="line"><span class="preprocessor">    H.at&lt;float&gt;(1,0) = (float)(y);\</span></div><div class="line"><span class="preprocessor">    H.at&lt;float&gt;(2,0) = 1.;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define GET_HOMO_VALUES(X, x, y)\</span></div><div class="line"><span class="preprocessor">    (x) = static_cast&lt;float&gt; (X.at&lt;float&gt;(0,0)/X.at&lt;float&gt;(2,0));\</span></div><div class="line"><span class="preprocessor">    (y) = static_cast&lt;float&gt; (X.at&lt;float&gt;(1,0)/X.at&lt;float&gt;(2,0));</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">const</span> std::string keys =</div><div class="line">    <span class="stringliteral">&quot;{@inputImage    | fruits.jpg    | input image filename }&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@templateImage |               | template image filename (optional)}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@inputWarp     |               | input warp (matrix) filename (optional)}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{n numOfIter    | 50            | ECC&#39;s iterations }&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{e epsilon      | 0.0001        | ECC&#39;s convergence epsilon }&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{o outputWarp   | outWarp.ecc   | output warp (matrix) filename }&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{m motionType   | affine        | type of motion (translation, euclidean, affine, homography) }&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{v verbose      | 1             | display initial and final images }&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{w warpedImfile | warpedECC.png | warped input image }&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{h help | | print help message }&quot;</span></div><div class="line">;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> help(<span class="keyword">const</span> <span class="keywordtype">char</span>** argv)</div><div class="line">{</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;\nThis file demonstrates the use of the ECC image alignment algorithm. When one image&quot;</span></div><div class="line">        <span class="stringliteral">&quot; is given, the template image is artificially formed by a random warp. When both images&quot;</span></div><div class="line">        <span class="stringliteral">&quot; are given, the initialization of the warp by command line parsing is possible. &quot;</span></div><div class="line">        <span class="stringliteral">&quot;If inputWarp is missing, the identity transformation initializes the algorithm. \n&quot;</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;\nUsage example (one image): \n&quot;</span></div><div class="line">         &lt;&lt; argv[0]</div><div class="line">         &lt;&lt; <span class="stringliteral">&quot; fruits.jpg -o=outWarp.ecc &quot;</span></div><div class="line">            <span class="stringliteral">&quot;-m=euclidean -e=1e-6 -N=70 -v=1 \n&quot;</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;\nUsage example (two images with initialization): \n&quot;</span></div><div class="line">         &lt;&lt; argv[0]</div><div class="line">         &lt;&lt; <span class="stringliteral">&quot; yourInput.png yourTemplate.png &quot;</span></div><div class="line">        <span class="stringliteral">&quot;yourInitialWarp.ecc -o=outWarp.ecc -m=homography -e=1e-6 -N=70 -v=1 -w=yourFinalImage.png \n&quot;</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> readWarp(<span class="keywordtype">string</span> iFilename, <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>&amp; warp, <span class="keywordtype">int</span> motionType){</div><div class="line"></div><div class="line">    <span class="comment">// it reads from file a specific number of raw values:</span></div><div class="line">    <span class="comment">// 9 values for homography, 6 otherwise</span></div><div class="line">    <a name="a1"></a><a class="code" href="../../db/de0/group__core__utils.html#gaf62bcd90f70e275191ab95136d85906b">CV_Assert</a>(warp.<a name="a2"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#af2d2652e552d7de635988f18a84b53e5">type</a>()==<a name="a3"></a><a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32ec76240e43e4c9c7b2e2785180a7e6">CV_32FC1</a>);</div><div class="line">    <span class="keywordtype">int</span> numOfElements;</div><div class="line">    <span class="keywordflow">if</span> (motionType==<a name="a4"></a><a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a81a5e999a7fde5656ce1ca0458741b27">MOTION_HOMOGRAPHY</a>)</div><div class="line">        numOfElements=9;</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">        numOfElements=6;</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> i;</div><div class="line">    <span class="keywordtype">int</span> ret_value;</div><div class="line"></div><div class="line">    ifstream myfile(iFilename.c_str());</div><div class="line">    <span class="keywordflow">if</span> (myfile.is_open()){</div><div class="line">        <span class="keywordtype">float</span>* matPtr = warp.<a name="a5"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#a13acd320291229615ef15f96ff1ff738">ptr</a>&lt;<span class="keywordtype">float</span>&gt;(0);</div><div class="line">        <span class="keywordflow">for</span>(i=0; i&lt;numOfElements; i++){</div><div class="line">            myfile &gt;&gt; matPtr[i];</div><div class="line">        }</div><div class="line">        ret_value = 1;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span> {</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Unable to open file &quot;</span> &lt;&lt; iFilename.c_str() &lt;&lt; endl;</div><div class="line">        ret_value = 0;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> ret_value;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> saveWarp(<span class="keywordtype">string</span> fileName, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>&amp; warp, <span class="keywordtype">int</span> motionType)</div><div class="line">{</div><div class="line">    <span class="comment">// it saves the raw matrix elements in a file</span></div><div class="line">    <a class="code" href="../../db/de0/group__core__utils.html#gaf62bcd90f70e275191ab95136d85906b">CV_Assert</a>(warp.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#af2d2652e552d7de635988f18a84b53e5">type</a>()==<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32ec76240e43e4c9c7b2e2785180a7e6">CV_32FC1</a>);</div><div class="line"></div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">float</span>* matPtr = warp.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#a13acd320291229615ef15f96ff1ff738">ptr</a>&lt;<span class="keywordtype">float</span>&gt;(0);</div><div class="line">    <span class="keywordtype">int</span> ret_value;</div><div class="line"></div><div class="line">    ofstream outfile(fileName.c_str());</div><div class="line">    <span class="keywordflow">if</span>( !outfile ) {</div><div class="line">        cerr &lt;&lt; <span class="stringliteral">&quot;error in saving &quot;</span></div><div class="line">            &lt;&lt; <span class="stringliteral">&quot;Couldn&#39;t open file &#39;&quot;</span> &lt;&lt; fileName.c_str() &lt;&lt; <span class="stringliteral">&quot;&#39;!&quot;</span> &lt;&lt; endl;</div><div class="line">        ret_value = 0;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span> {<span class="comment">//save the warp&#39;s elements</span></div><div class="line">        outfile &lt;&lt; matPtr[0] &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; matPtr[1] &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; matPtr[2] &lt;&lt; endl;</div><div class="line">        outfile &lt;&lt; matPtr[3] &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; matPtr[4] &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; matPtr[5] &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">if</span> (motionType==<a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a81a5e999a7fde5656ce1ca0458741b27">MOTION_HOMOGRAPHY</a>){</div><div class="line">            outfile &lt;&lt; matPtr[6] &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; matPtr[7] &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; matPtr[8] &lt;&lt; endl;</div><div class="line">        }</div><div class="line">        ret_value = 1;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> ret_value;</div><div class="line"></div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> draw_warped_roi(<a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>&amp; image, <span class="keyword">const</span> <span class="keywordtype">int</span> width, <span class="keyword">const</span> <span class="keywordtype">int</span> height, <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>&amp; W)</div><div class="line">{</div><div class="line">    <a name="_a6"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html">Point2f</a> top_left, top_right, bottom_left, bottom_right;</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>  H = <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> (3, 1, <a name="a7"></a><a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga4a3def5d72b74bed31f5f8ab7676099c">CV_32F</a>);</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>  U = <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> (3, 1, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga4a3def5d72b74bed31f5f8ab7676099c">CV_32F</a>);</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> warp_mat = <a name="a8"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#a2cf9b9acde7a9852542bbc20ef851ed2">Mat::eye</a> (3, 3, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga4a3def5d72b74bed31f5f8ab7676099c">CV_32F</a>);</div><div class="line"></div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y = 0; y &lt; W.<a name="a9"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>; y++)</div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = 0; x &lt; W.<a name="a10"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>; x++)</div><div class="line">            warp_mat.<a name="a11"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<span class="keywordtype">float</span>&gt;(y,x) = W.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<span class="keywordtype">float</span>&gt;(y,x);</div><div class="line"></div><div class="line">    <span class="comment">//warp the corners of rectangle</span></div><div class="line"></div><div class="line">    <span class="comment">// top-left</span></div><div class="line">    HOMO_VECTOR(H, 1, 1);</div><div class="line">    <a name="a12"></a><a class="code" href="../../d2/de8/group__core__array.html#gacb6e64071dffe36434e1e7ee79e7cb35">gemm</a>(warp_mat, H, 1, 0, 0, U);</div><div class="line">    GET_HOMO_VALUES(U, top_left.<a name="a13"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>, top_left.<a name="a14"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>);</div><div class="line"></div><div class="line">    <span class="comment">// top-right</span></div><div class="line">    HOMO_VECTOR(H, width, 1);</div><div class="line">    <a class="code" href="../../d2/de8/group__core__array.html#gacb6e64071dffe36434e1e7ee79e7cb35">gemm</a>(warp_mat, H, 1, 0, 0, U);</div><div class="line">    GET_HOMO_VALUES(U, top_right.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>, top_right.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>);</div><div class="line"></div><div class="line">    <span class="comment">// bottom-left</span></div><div class="line">    HOMO_VECTOR(H, 1, height);</div><div class="line">    <a class="code" href="../../d2/de8/group__core__array.html#gacb6e64071dffe36434e1e7ee79e7cb35">gemm</a>(warp_mat, H, 1, 0, 0, U);</div><div class="line">    GET_HOMO_VALUES(U, bottom_left.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>, bottom_left.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>);</div><div class="line"></div><div class="line">    <span class="comment">// bottom-right</span></div><div class="line">    HOMO_VECTOR(H, width, height);</div><div class="line">    <a class="code" href="../../d2/de8/group__core__array.html#gacb6e64071dffe36434e1e7ee79e7cb35">gemm</a>(warp_mat, H, 1, 0, 0, U);</div><div class="line">    GET_HOMO_VALUES(U, bottom_right.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>, bottom_right.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>);</div><div class="line"></div><div class="line">    <span class="comment">// draw the warped perimeter</span></div><div class="line">    <a name="a15"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga7078a9fae8c7e7d13d24dac2520ae4a2">line</a>(image, top_left, top_right, <a name="a16"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255));</div><div class="line">    <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga7078a9fae8c7e7d13d24dac2520ae4a2">line</a>(image, top_right, bottom_right, <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255));</div><div class="line">    <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga7078a9fae8c7e7d13d24dac2520ae4a2">line</a>(image, bottom_right, bottom_left, <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255));</div><div class="line">    <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga7078a9fae8c7e7d13d24dac2520ae4a2">line</a>(image, bottom_left, top_left, <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255));</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main (<span class="keyword">const</span> <span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span> * argv[])</div><div class="line">{</div><div class="line"></div><div class="line">    <a name="_a17"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">CommandLineParser</a> parser(argc, argv, keys);</div><div class="line">    parser.about(<span class="stringliteral">&quot;ECC demo&quot;</span>);</div><div class="line"></div><div class="line">    parser.printMessage();</div><div class="line">    help(argv);</div><div class="line"></div><div class="line">    <span class="keywordtype">string</span> imgFile = parser.get&lt;<span class="keywordtype">string</span>&gt;(0);</div><div class="line">    <span class="keywordtype">string</span> tempImgFile = parser.get&lt;<span class="keywordtype">string</span>&gt;(1);</div><div class="line">    <span class="keywordtype">string</span> inWarpFile = parser.get&lt;<span class="keywordtype">string</span>&gt;(2);</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> number_of_iterations = parser.get&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;n&quot;</span>);</div><div class="line">    <span class="keywordtype">double</span> termination_eps = parser.get&lt;<span class="keywordtype">double</span>&gt;(<span class="stringliteral">&quot;e&quot;</span>);</div><div class="line">    <span class="keywordtype">string</span> warpType = parser.get&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;m&quot;</span>);</div><div class="line">    <span class="keywordtype">int</span> verbose = parser.get&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;v&quot;</span>);</div><div class="line">    <span class="keywordtype">string</span> finalWarp = parser.get&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;o&quot;</span>);</div><div class="line">    <span class="keywordtype">string</span> warpedImFile = parser.get&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;w&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span> (!parser.check())</div><div class="line">    {</div><div class="line">        parser.printErrors();</div><div class="line">        <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> (!(warpType == <span class="stringliteral">&quot;translation&quot;</span> || warpType == <span class="stringliteral">&quot;euclidean&quot;</span></div><div class="line">        || warpType == <span class="stringliteral">&quot;affine&quot;</span> || warpType == <span class="stringliteral">&quot;homography&quot;</span>))</div><div class="line">    {</div><div class="line">        cerr &lt;&lt; <span class="stringliteral">&quot;Invalid motion transformation&quot;</span> &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> mode_temp;</div><div class="line">    <span class="keywordflow">if</span> (warpType == <span class="stringliteral">&quot;translation&quot;</span>)</div><div class="line">        mode_temp = <a name="a18"></a><a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a01106d6d20122b782ff25eaeffe9a5be">MOTION_TRANSLATION</a>;</div><div class="line">    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (warpType == <span class="stringliteral">&quot;euclidean&quot;</span>)</div><div class="line">        mode_temp = <a name="a19"></a><a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a075fb2a93001cb4cc1ba1b22af1e8848">MOTION_EUCLIDEAN</a>;</div><div class="line">    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (warpType == <span class="stringliteral">&quot;affine&quot;</span>)</div><div class="line">        mode_temp = <a name="a20"></a><a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88aa22eb135b6afe090a8a0d228fd62634a">MOTION_AFFINE</a>;</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">        mode_temp = <a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a81a5e999a7fde5656ce1ca0458741b27">MOTION_HOMOGRAPHY</a>;</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> inputImage = <a name="a21"></a><a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>(<a name="a22"></a><a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>(imgFile), <a name="a23"></a><a class="code" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80ae29981cfc153d3b0cef5c0daeedd2125">IMREAD_GRAYSCALE</a>);</div><div class="line">    <span class="keywordflow">if</span> (inputImage.<a name="a24"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>())</div><div class="line">    {</div><div class="line">        cerr &lt;&lt; <span class="stringliteral">&quot;Unable to load the inputImage&quot;</span> &lt;&lt;  endl;</div><div class="line">        <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> target_image;</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> template_image;</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (tempImgFile!=<span class="stringliteral">&quot;&quot;</span>) {</div><div class="line">        inputImage.<a name="a25"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77">copyTo</a>(target_image);</div><div class="line">        template_image = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>(<a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>(tempImgFile), <a class="code" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80ae29981cfc153d3b0cef5c0daeedd2125">IMREAD_GRAYSCALE</a>);</div><div class="line">        <span class="keywordflow">if</span> (template_image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>()){</div><div class="line">            cerr &lt;&lt; <span class="stringliteral">&quot;Unable to load the template image&quot;</span> &lt;&lt; endl;</div><div class="line">            <span class="keywordflow">return</span> -1;</div><div class="line">        }</div><div class="line"></div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span>{ <span class="comment">//apply random warp to input image</span></div><div class="line">        <a name="a26"></a><a class="code" href="../../da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d">resize</a>(inputImage, target_image, <a name="a27"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(216, 216), 0, 0, <a name="a28"></a><a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac00f4a8155563cdc23437fc0959da935">INTER_LINEAR_EXACT</a>);</div><div class="line">        <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> warpGround;</div><div class="line">        <a name="_a29"></a><a class="code" href="../../d1/dd6/classcv_1_1RNG.html">RNG</a> rng(<a name="a30"></a><a class="code" href="../../db/de0/group__core__utils.html#gae73f58000611a1af25dd36d496bf4487">getTickCount</a>());</div><div class="line">        <span class="keywordtype">double</span> angle;</div><div class="line">        <span class="keywordflow">switch</span> (mode_temp) {</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a01106d6d20122b782ff25eaeffe9a5be">MOTION_TRANSLATION</a>:</div><div class="line">            warpGround = (<a name="_a31"></a><a class="code" href="../../df/dfc/classcv_1_1Mat__.html">Mat_&lt;float&gt;</a>(2,3) &lt;&lt; 1, 0, (rng.uniform(10.f, 20.f)),</div><div class="line">                0, 1, (rng.uniform(10.f, 20.f)));</div><div class="line">            <a name="a32"></a><a class="code" href="../../da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983">warpAffine</a>(target_image, template_image, warpGround,</div><div class="line">                <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(200,200), <a name="a33"></a><a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac97d8e4880d8b5d509e96825c7522deb">INTER_LINEAR</a> + <a name="a34"></a><a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa48be1c433186c4eae1ea86aa0ca75ba">WARP_INVERSE_MAP</a>);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a075fb2a93001cb4cc1ba1b22af1e8848">MOTION_EUCLIDEAN</a>:</div><div class="line">            angle = <a name="a35"></a><a class="code" href="../../db/de0/group__core__utils.html#ga677b89fae9308b340ddaebf0dba8455f">CV_PI</a>/30 + <a class="code" href="../../db/de0/group__core__utils.html#ga677b89fae9308b340ddaebf0dba8455f">CV_PI</a>*rng.uniform((<span class="keywordtype">double</span>)-2.f, (<span class="keywordtype">double</span>)2.f)/180;</div><div class="line"></div><div class="line">            warpGround = (<a class="code" href="../../df/dfc/classcv_1_1Mat__.html">Mat_&lt;float&gt;</a>(2,3) &lt;&lt; <a name="a36"></a><a class="code" href="../../d0/de1/group__core.html#gaf0f2fe47183d063fb7415097fbadb570">cos</a>(angle), -<a name="a37"></a><a class="code" href="../../d0/de1/group__core.html#ga53a8656033a51db64caa72ee9d4e93b4">sin</a>(angle), (rng.uniform(10.f, 20.f)),</div><div class="line">                <a class="code" href="../../d0/de1/group__core.html#ga53a8656033a51db64caa72ee9d4e93b4">sin</a>(angle), <a class="code" href="../../d0/de1/group__core.html#gaf0f2fe47183d063fb7415097fbadb570">cos</a>(angle), (rng.uniform(10.f, 20.f)));</div><div class="line">            <a class="code" href="../../da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983">warpAffine</a>(target_image, template_image, warpGround,</div><div class="line">                <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(200,200), <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac97d8e4880d8b5d509e96825c7522deb">INTER_LINEAR</a> + <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa48be1c433186c4eae1ea86aa0ca75ba">WARP_INVERSE_MAP</a>);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88aa22eb135b6afe090a8a0d228fd62634a">MOTION_AFFINE</a>:</div><div class="line"></div><div class="line">            warpGround = (<a class="code" href="../../df/dfc/classcv_1_1Mat__.html">Mat_&lt;float&gt;</a>(2,3) &lt;&lt; (1-rng.uniform(-0.05f, 0.05f)),</div><div class="line">                (rng.uniform(-0.03f, 0.03f)), (rng.uniform(10.f, 20.f)),</div><div class="line">                (rng.uniform(-0.03f, 0.03f)), (1-rng.uniform(-0.05f, 0.05f)),</div><div class="line">                (rng.uniform(10.f, 20.f)));</div><div class="line">            <a class="code" href="../../da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983">warpAffine</a>(target_image, template_image, warpGround,</div><div class="line">                <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(200,200), <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac97d8e4880d8b5d509e96825c7522deb">INTER_LINEAR</a> + <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa48be1c433186c4eae1ea86aa0ca75ba">WARP_INVERSE_MAP</a>);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a81a5e999a7fde5656ce1ca0458741b27">MOTION_HOMOGRAPHY</a>:</div><div class="line">            warpGround = (<a class="code" href="../../df/dfc/classcv_1_1Mat__.html">Mat_&lt;float&gt;</a>(3,3) &lt;&lt; (1-rng.uniform(-0.05f, 0.05f)),</div><div class="line">                (rng.uniform(-0.03f, 0.03f)), (rng.uniform(10.f, 20.f)),</div><div class="line">                (rng.uniform(-0.03f, 0.03f)), (1-rng.uniform(-0.05f, 0.05f)),(rng.uniform(10.f, 20.f)),</div><div class="line">                (rng.uniform(0.0001f, 0.0003f)), (rng.uniform(0.0001f, 0.0003f)), 1.f);</div><div class="line">            <a name="a38"></a><a class="code" href="../../da/d54/group__imgproc__transform.html#gaf73673a7e8e18ec6963e3774e6a94b87">warpPerspective</a>(target_image, template_image, warpGround,</div><div class="line">                <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(200,200), <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac97d8e4880d8b5d509e96825c7522deb">INTER_LINEAR</a> + <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa48be1c433186c4eae1ea86aa0ca75ba">WARP_INVERSE_MAP</a>);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">    }</div><div class="line"></div><div class="line"></div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">int</span> warp_mode = mode_temp;</div><div class="line"></div><div class="line">    <span class="comment">// initialize or load the warp matrix</span></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> warp_matrix;</div><div class="line">    <span class="keywordflow">if</span> (warpType == <span class="stringliteral">&quot;homography&quot;</span>)</div><div class="line">        warp_matrix = <a class="code" href="../../d3/d63/classcv_1_1Mat.html#a2cf9b9acde7a9852542bbc20ef851ed2">Mat::eye</a>(3, 3, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga4a3def5d72b74bed31f5f8ab7676099c">CV_32F</a>);</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">        warp_matrix = <a class="code" href="../../d3/d63/classcv_1_1Mat.html#a2cf9b9acde7a9852542bbc20ef851ed2">Mat::eye</a>(2, 3, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga4a3def5d72b74bed31f5f8ab7676099c">CV_32F</a>);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (inWarpFile!=<span class="stringliteral">&quot;&quot;</span>){</div><div class="line">        <span class="keywordtype">int</span> readflag = readWarp(inWarpFile, warp_matrix, warp_mode);</div><div class="line">        <span class="keywordflow">if</span> ((!readflag) || warp_matrix.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>())</div><div class="line">        {</div><div class="line">            cerr &lt;&lt; <span class="stringliteral">&quot;-&gt; Check warp initialization file&quot;</span> &lt;&lt; endl &lt;&lt; flush;</div><div class="line">            <span class="keywordflow">return</span> -1;</div><div class="line">        }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span> {</div><div class="line"></div><div class="line">        printf(<span class="stringliteral">&quot;\n -&gt;Performance Warning: Identity warp ideally assumes images of &quot;</span></div><div class="line">            <span class="stringliteral">&quot;similar size. If the deformation is strong, the identity warp may not &quot;</span></div><div class="line">            <span class="stringliteral">&quot;be a good initialization. \n&quot;</span>);</div><div class="line"></div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (number_of_iterations &gt; 200)</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;-&gt; Warning: too many iterations &quot;</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (warp_mode != <a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a81a5e999a7fde5656ce1ca0458741b27">MOTION_HOMOGRAPHY</a>)</div><div class="line">        warp_matrix.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a> = 2;</div><div class="line"></div><div class="line">    <span class="comment">// start timing</span></div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">double</span> tic_init = (double) <a class="code" href="../../db/de0/group__core__utils.html#gae73f58000611a1af25dd36d496bf4487">getTickCount</a> ();</div><div class="line">    <span class="keywordtype">double</span> cc = <a name="a39"></a><a class="code" href="../../dc/d6b/group__video__track.html#ga1aa357007eaec11e9ed03500ecbcbe47">findTransformECC</a> (template_image, target_image, warp_matrix, warp_mode,</div><div class="line">        <a name="_a40"></a><a class="code" href="../../d9/d5d/classcv_1_1TermCriteria.html">TermCriteria</a> (<a name="a41"></a><a class="code" href="../../d9/d5d/classcv_1_1TermCriteria.html#a56fecdc291ccaba8aad27d67ccf72c57aeb9da694ea67b3ef7d524521b580867d">TermCriteria::COUNT</a>+<a name="a42"></a><a class="code" href="../../d9/d5d/classcv_1_1TermCriteria.html#a56fecdc291ccaba8aad27d67ccf72c57a857609e73e7028e638d2ea649f3b45d5">TermCriteria::EPS</a>,</div><div class="line">        number_of_iterations, termination_eps));</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (cc == -1)</div><div class="line">    {</div><div class="line">        cerr &lt;&lt; <span class="stringliteral">&quot;The execution was interrupted. The correlation value is going to be minimized.&quot;</span> &lt;&lt; endl;</div><div class="line">        cerr &lt;&lt; <span class="stringliteral">&quot;Check the warp initialization and/or the size of images.&quot;</span> &lt;&lt; endl &lt;&lt; flush;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// end timing</span></div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">double</span> toc_final  = (double) <a class="code" href="../../db/de0/group__core__utils.html#gae73f58000611a1af25dd36d496bf4487">getTickCount</a> ();</div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">double</span> total_time = (toc_final-tic_init)/(<a name="a43"></a><a class="code" href="../../db/de0/group__core__utils.html#ga705441a9ef01f47acdc55d87fbe5090c">getTickFrequency</a>());</div><div class="line">    <span class="keywordflow">if</span> (verbose){</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Alignment time (&quot;</span> &lt;&lt; warpType &lt;&lt; <span class="stringliteral">&quot; transformation): &quot;</span></div><div class="line">            &lt;&lt; total_time &lt;&lt; <span class="stringliteral">&quot; sec&quot;</span> &lt;&lt; endl &lt;&lt; flush;</div><div class="line">        <span class="comment">//  cout &lt;&lt; &quot;Final correlation: &quot; &lt;&lt; cc &lt;&lt; endl &lt;&lt; flush;</span></div><div class="line"></div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// save the final warp matrix</span></div><div class="line">    saveWarp(finalWarp, warp_matrix, warp_mode);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (verbose){</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;\nThe final warp has been saved in the file: &quot;</span> &lt;&lt; finalWarp &lt;&lt; endl &lt;&lt; flush;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// save the final warped image</span></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> warped_image = <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>(template_image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>, template_image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32ec76240e43e4c9c7b2e2785180a7e6">CV_32FC1</a>);</div><div class="line">    <span class="keywordflow">if</span> (warp_mode != <a class="code" href="../../dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a81a5e999a7fde5656ce1ca0458741b27">MOTION_HOMOGRAPHY</a>)</div><div class="line">        <a class="code" href="../../da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983">warpAffine</a>      (target_image, warped_image, warp_matrix, warped_image.<a name="a44"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#a146f8e8dda07d1365a575ab83d9828d1">size</a>(),</div><div class="line">        <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac97d8e4880d8b5d509e96825c7522deb">INTER_LINEAR</a> + <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa48be1c433186c4eae1ea86aa0ca75ba">WARP_INVERSE_MAP</a>);</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">        <a class="code" href="../../da/d54/group__imgproc__transform.html#gaf73673a7e8e18ec6963e3774e6a94b87">warpPerspective</a> (target_image, warped_image, warp_matrix, warped_image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#a146f8e8dda07d1365a575ab83d9828d1">size</a>(),</div><div class="line">        <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121ac97d8e4880d8b5d509e96825c7522deb">INTER_LINEAR</a> + <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa48be1c433186c4eae1ea86aa0ca75ba">WARP_INVERSE_MAP</a>);</div><div class="line"></div><div class="line">    <span class="comment">//save the warped image</span></div><div class="line">    <a name="a45"></a><a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(warpedImFile, warped_image);</div><div class="line"></div><div class="line">    <span class="comment">// display resulting images</span></div><div class="line">    <span class="keywordflow">if</span> (verbose)</div><div class="line">    {</div><div class="line"></div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;The warped image has been saved in the file: &quot;</span> &lt;&lt; warpedImFile &lt;&lt; endl &lt;&lt; flush;</div><div class="line"></div><div class="line">        <a name="a46"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow</a> (<span class="stringliteral">&quot;image&quot;</span>,    <a name="a47"></a><a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3acf621ace7a54954cbac01df27e47228f">WINDOW_AUTOSIZE</a>);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow</a> (<span class="stringliteral">&quot;template&quot;</span>, <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3acf621ace7a54954cbac01df27e47228f">WINDOW_AUTOSIZE</a>);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow</a> (<span class="stringliteral">&quot;warped image&quot;</span>,   <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3acf621ace7a54954cbac01df27e47228f">WINDOW_AUTOSIZE</a>);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow</a> (<span class="stringliteral">&quot;error (black: no error)&quot;</span>, <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3acf621ace7a54954cbac01df27e47228f">WINDOW_AUTOSIZE</a>);</div><div class="line"></div><div class="line">        <a name="a48"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">moveWindow</a>  (<span class="stringliteral">&quot;image&quot;</span>, 20, 300);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">moveWindow</a>  (<span class="stringliteral">&quot;template&quot;</span>, 300, 300);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">moveWindow</a>  (<span class="stringliteral">&quot;warped image&quot;</span>,   600, 300);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">moveWindow</a>  (<span class="stringliteral">&quot;error (black: no error)&quot;</span>, 900, 300);</div><div class="line"></div><div class="line">        <span class="comment">// draw boundaries of corresponding regions</span></div><div class="line">        <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> identity_matrix = <a class="code" href="../../d3/d63/classcv_1_1Mat.html#a2cf9b9acde7a9852542bbc20ef851ed2">Mat::eye</a>(3,3,<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga4a3def5d72b74bed31f5f8ab7676099c">CV_32F</a>);</div><div class="line"></div><div class="line">        draw_warped_roi (target_image,   template_image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>-2, template_image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>-2, warp_matrix);</div><div class="line">        draw_warped_roi (template_image, template_image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>-2, template_image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>-2, identity_matrix);</div><div class="line"></div><div class="line">        <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> errorImage;</div><div class="line">        <a name="a49"></a><a class="code" href="../../d2/de8/group__core__array.html#gaa0f00d98b4b5edeaeb7b8333b2de353b">subtract</a>(template_image, warped_image, errorImage);</div><div class="line">        <span class="keywordtype">double</span> max_of_error;</div><div class="line">        <a name="a50"></a><a class="code" href="../../d2/de8/group__core__array.html#gab473bf2eb6d14ff97e89b355dac20707">minMaxLoc</a>(errorImage, NULL, &amp;max_of_error);</div><div class="line"></div><div class="line">        <span class="comment">// show images</span></div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Press any key to exit the demo (you might need to click on the images before).&quot;</span> &lt;&lt; endl &lt;&lt; flush;</div><div class="line"></div><div class="line">        <a name="a51"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a> (<span class="stringliteral">&quot;image&quot;</span>,    target_image);</div><div class="line">        <a name="a52"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a> (200);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a> (<span class="stringliteral">&quot;template&quot;</span>, template_image);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a> (200);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a> (<span class="stringliteral">&quot;warped image&quot;</span>,   warped_image);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(200);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a> (<span class="stringliteral">&quot;error (black: no error)&quot;</span>,  <a name="a53"></a><a class="code" href="../../d2/d75/namespacecv.html#af6df65b17fb11af6d34634b6dfa44683">abs</a>(errorImage)*255/max_of_error);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div><div class="line"></div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// done</span></div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:29 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
